<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""DTD/xhtml1-strict.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Account67</title>
		<c:import url="/includes/css_inc.jsp" />
		<c:import url="/includes/js_inc.jsp" />
		<script>
			if (top.frames.length != 0) {
				top.location = self.document.location;
			}
			$(function() {
				var result = false;
				$("#save").button({
		            icons: {
		                primary: "ui-icon-disk"
		            }
		        }).click(function(){
		        	if ($("#rePasswd").val() != $("#oldPasswd").val()) {
						document.getElementById("errorMessage").innerHTML = "รหัสเดิมไม่ถูกต้อง";
		        		$("#rePasswd").val("");
		        		$("#rePasswd").focus();
		        		result = false;
		        	} else if ($("#newPasswd").val() != $("#passwd").val()){
						document.getElementById("errorMessage").innerHTML = "รหัสไม่ตรงกัน";
		        		$("#passwd").val("");
		        		$("#passwd").focus();
		        		result = false;
		        	} else if ($("#oldPasswd").val() == $("#passwd").val()){
						document.getElementById("errorMessage").innerHTML = "รหัสใหม่ตรงกับรหัสเดิม";
		        		$("#passwd").val("");
		        		$("#passwd").focus();
		        		result = false;
		        	} else {
		        		result = true;
		        	}
		        	if (result && validateEmpty()) {
		        		$("#saveForm").submit();
		        	}
		        });

				$( "#dialog-login" ).dialog({
					autoOpen: true,
					height: 370,
					width: 480,
					modal: true,
					draggable: false,
					resizable: false,
					closeOnEscape: false,
					open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
				});
				
			});

			function validatePassword(object) {
				var p = object.value;
				var errors = "";
				if(object.value != null && object.value != ""){
					if (p.length < 8) {
						errors += "รหัสผ่านต้องไม่น้อยกว่า 8 หลัก <br/>";
					}
					if (p.search(/(?=.*\d)/) < 0) {
						errors += "รหัสผ่านต้อง ประกอบด้วยตัวเลข <br/>";
					}
					if (p.search(/(?=.*[a-z])/) < 0) {
						errors += "รหัสผ่านต้อง ประกอบด้วยอักษรตัวเล็ก <br/>";
					}
					if (p.search(/(?=.*[A-Z])/) < 0) {
						errors += "รหัสผ่านต้อง ประกอบด้วยอักษรตัวใหญ่ <br/>";
					}
					if (errors.length > 0) {
						document.getElementById("errorMessage").innerHTML = errors;
						object.value = "";
						object.focus();
						return false;
					} else {
						document.getElementById("errorMessage").innerHTML = "";
						return true;
					}
				}
			}
		</script>
	</head>
	<body>
		<div id="dialog-login" title="เปลี่ยนรหัสผ่าน" style="overflow: hidden;">
			<form action="${pageContext.request.contextPath}/acc67" method="post" name="saveForm" id="saveForm">
				<input type="hidden" name="app" value="ACC670000" />
				<input type="hidden" name="job" value="repasswd" />
				<input type="hidden"  name="oldPasswd" id="oldPasswd" value="${passwd}"/>
				<input type="hidden"  name="userId" id="userId" value="${userId}"/>
				<table width="100%" cellpadding="2" cellspacing="2">
					<tr>
						<td colspan="3" align="center" height="80px">
							<span id="errorMessage" class="red"></span>
						</td>
					</tr>
					<tr>
						<td width="15%">&nbsp;</td>
						<td width="23%" align="right">รหัสผู้ใช้ระบบ : </td>
						<td>${userId}</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td align="right">รหัสผ่านเดิม</td>
						<td>
							<input type="password"  name="rePasswd" id="rePasswd" size="15" maxlength="15"/>
						</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td align="right">รหัสผ่านใหม่</td>
						<td>
							<input type="password"  name="newPasswd" id="newPasswd" size="15" maxlength="15" onblur="validatePassword(this)"/>
							<span class="red" id="#newPasswd">*</span>
						</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td align="right">ยืนยันรหัสผ่านใหม่</td>
						<td>
							<input type="password"  name="passwd" id="passwd" size="15" maxlength="15"  onblur="validatePassword(this)"/>
							<span class="red" id="#passwd">*</span>
						</td>
					</tr>
					<tr>
						<td colspan="3" align="center"><button id="save" type="button" class="acc67-button">บันทึก</button></td>
					</tr>
				</table>
			</form>
		</div>
	</body>
</html>